import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.ListIterator;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JFrameRetirarEstudiante extends javax.swing.JDialog {
	private JPanel jPanelRetirarEstudiante;
	private JButton jButtonBuscarRetirar;
	private JTextField jTextFieldCEdulaRetirar;
	private JLabel jLabelCedulaRetirar;
	int opc, cedula;
	private Seccion secc;
	private JLabel fdg;
	private JButton jButtonSalir65;
	LinkedList<Estudiante> LisEstu1;
	private Estudiante estu;


	
	public JFrameRetirarEstudiante(JFrame frame, Seccion secci) {
		super(frame);
		initGUI();
		secc=secci;
		LisEstu1 = secc.listarEstudiantesCedula();
	}
	
	private void initGUI() {
		try {
			setModal(true);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Retirar Estudiantes");
			{
				jPanelRetirarEstudiante = new JPanel();
				getContentPane().add(jPanelRetirarEstudiante);
				jPanelRetirarEstudiante.setBounds(20, 18, 711, 211);
				jPanelRetirarEstudiante.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				jPanelRetirarEstudiante.setLayout(null);
				{
					jLabelCedulaRetirar = new JLabel();
					jPanelRetirarEstudiante.add(jLabelCedulaRetirar);
					jLabelCedulaRetirar.setText("Cedula del estudiante ");
					jLabelCedulaRetirar.setBounds(39, 72, 216, 22);
					jLabelCedulaRetirar.setFont(new java.awt.Font("Comic Sans MS",3,14));
				}
				{
					jTextFieldCEdulaRetirar = new JTextField();
					jPanelRetirarEstudiante.add(jTextFieldCEdulaRetirar);
					jTextFieldCEdulaRetirar.setBounds(273, 73, 120, 22);
					jTextFieldCEdulaRetirar.setFont(new java.awt.Font("Comic Sans MS",3,14));
				}
				{
					jButtonBuscarRetirar = new JButton();
					jPanelRetirarEstudiante.add(jButtonBuscarRetirar);
					jButtonBuscarRetirar.setText("Retirar");
					jButtonBuscarRetirar.setBounds(428, 73, 102, 22);
					jButtonBuscarRetirar.setFont(new java.awt.Font("Comic Sans MS",3,14));
					jButtonBuscarRetirar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtonBuscarRetirarActionPerformed(evt);								
						}
					});  
				}
				{
					jButtonSalir65 = new JButton();
					jPanelRetirarEstudiante.add(jButtonSalir65);
					jButtonSalir65.setText("Salir");
					jButtonSalir65.setBounds(309, 161, 101, 22);
					jButtonSalir65.setFont(new java.awt.Font("Comic Sans MS",3,14));
					jButtonSalir65.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtonSalir65ActionPerformed(evt);								
						}
					}); 
				}
				{
					fdg = new JLabel();
					jPanelRetirarEstudiante.add(fdg);
					fdg.setText("Retirar Estudiante");
					fdg.setBounds(270, 13, 153, 15);
					fdg.setFont(new java.awt.Font("Comic Sans MS",3,14));
				}
			}
			pack();
			this.setSize(754, 281);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}


	private void jButtonSalir65ActionPerformed(ActionEvent evt) {
		   this.dispose();
		
	}

	private void jButtonBuscarRetirarActionPerformed(ActionEvent evt) {
				
		if(jTextFieldCEdulaRetirar.getText().trim().equals("")){
			JOptionPane.showMessageDialog(null, "Llene el campo cedula", "Informacion", JOptionPane.INFORMATION_MESSAGE);	
			}
		
		else if ( jTextFieldCEdulaRetirar.getText().matches( "[^0-9]*" ) )
		{
			JOptionPane.showMessageDialog(null, "La cedula debe ser valores numericos", "Informacion", JOptionPane.INFORMATION_MESSAGE);
			jTextFieldCEdulaRetirar.setText("");
			
			
		}
		
		ListIterator<Estudiante> it1 = LisEstu1.listIterator();
		cedula = Integer.parseInt(jTextFieldCEdulaRetirar.getText().trim());	
		while (it1.hasNext()) 
	   {
			Estudiante estu1 = it1.next();
			if (estu1.getCedula() == cedula) {
			    secc.retirarEstudiante(cedula);
				JOptionPane.showMessageDialog(null, "El estudiante fue retirado con exito", "Informacion", JOptionPane.INFORMATION_MESSAGE);
				jTextFieldCEdulaRetirar.setText("");
				return;
			}	
			
	   }
					
        JOptionPane.showMessageDialog(null, "La cedula del Estudiante no existe", "Informacion", JOptionPane.INFORMATION_MESSAGE);
        jTextFieldCEdulaRetirar.setText("");
			}
				
		}

